package com.cy.springcloudalibaba.producer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

/**
 * @Description: 发生消息
 * @ClassName: SendService
 * @Author: chenyu
 * @Date: 2025/3/3 14:41
 */
@Service
public class SendService {
    @Autowired
    private Source source;

    public void send(String msg) throws Exception {
        //source.output()返回消息通道
        boolean flag = source.output().send(MessageBuilder.withPayload(msg).build());
        System.out.println("消息发送：" + flag);
    }
}
